<?php 
namespace Admin\Controller;
use Think\Controller;

class LoginController extends Controller{
	//登录页面显示  验证登录
	public function login(){
		if(IS_GET){
			//显示页面
			$this->display();
		}else{
			//验证码验证
			$captcha = I("post.verify");
		    $verify = new \Think\Verify();
		   	$res =$verify->check($captcha);
		   	if(!$res){
		   		$this->error("验证码错误");
		   	}
		   	//接受账号密码
		   	$username = I("post.username");
		   	$password = I("post.password");
		   	$Model = D("Admin");
		   	$res = $Model->login($username,$password);
			if(!$res){
				$this->error($Model->getError());
			}
			$this->success("登录成功",U("Index/index"));
		}
	}
	//生成验证码
	public function verify(){
		$config = [
			"length"=>4
		];
		$verify = new \Think\Verify($config);
		$verify->entry();
	}
}